﻿using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using Xoohoo.Extensions;
using Xoohoo.Models.InputModels;
using XM = Xoohoo.Models;
using Xoohoo.Repositories.SqlServerEF.Entities;
using System.Data.Objects;

namespace Xoohoo.Repositories.SqlServerEF
{
    public abstract class RepositoryBase<TEntity> : IDisposable where TEntity : class
    {
        private XoohooContext _db = new XoohooContext();
        
        protected XoohooContext DB
        {
            get { return _db; }
        }

        protected DbSet<TEntity> DbSet
        {
            get { return DB.Set<TEntity>(); }
        }

        #region IDisposable Members

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    _db.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion

    }
}
